using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Reflection;
using System.Text;

namespace AresControls
{
	public class HSelection : HControl
	{
		private string m_DefaultStyle = "", m_PathPrefix = "", m_OnOpenSelection = "", m_DependentColumns = "", m_OnKeyDown = "", m_ImageUrl = "", m_InvokeOnDeleteValue = "";
		private bool m_PartialReadOnly;

		public HSelection()
		{
			m_DefaultStyle = ";font-size:8pt;font-family:Arial;margin:0;border:0;height:18px;color:#442200;background-color:#FFFFFF;text-align:left;";
			m_ImageUrl = "/Resources/Images/Tools/gr_sel.jpg";
			m_PartialReadOnly = false;
		}

		public string ImageUrl
		{
			get { return m_ImageUrl; }
			set { m_ImageUrl = value; }
		}		

		public string OnOpenSelection
		{
			get { return m_OnOpenSelection; }
			set { m_OnOpenSelection = value; }
		}

		public string OnKeyDown
		{
			get { return m_OnKeyDown; }
			set { m_OnKeyDown = value; }
		}

		public bool PartialReadOnly
		{
			get { return m_PartialReadOnly; }
			set { m_PartialReadOnly = value; }
		}

		public string DependentColumns
		{
			get { return m_DependentColumns; }
			set { m_DependentColumns = value; }
		}

		public string InvokeOnDeleteValue
		{
			get { return m_InvokeOnDeleteValue; }
			set { m_InvokeOnDeleteValue = value; }
		}

		public string renderInvokeOnDeleteValue()
		{
			return " InvokeOnDeleteValue=\"" + InvokeOnDeleteValue + "\" ";
		}

		private string PathPrefix
		{
			get { return m_PathPrefix; }
			set { m_PathPrefix = value; }
		}

		protected override void Render(HtmlTextWriter output)
		{
			StringBuilder sb = new StringBuilder();
			PathPrefix = Page.Request.ApplicationPath;

			if (PathPrefix == "/")
				PathPrefix = "";

			sb.Append("<input type=\"Text\" ControlType=\"HSelection\" ");
			sb.Append((ReadOnly)?"readonly ControlReadOnly=\"true\" ":"");
			Style += (ReadOnly)?";background-color:"+ReadOnlyColor:"";
			sb.Append((PartialReadOnly)?" readonly ControlPartialReadOnly=\"true\" ":"");
			Style = ((PartialReadOnly)?";background-color:"+ReadOnlyColor + ";":"") + Style;
			sb.Append((OnKeyDown != "")?" onkeydown=\"" + OnKeyDown + "\" ":"");
			sb.Append((DependentColumns != "")?" DependentColumns=\"" + DependentColumns + "\" ":"");
			sb.Append(" style=\"width:" + Width + m_DefaultStyle + Style + "\" ");
			sb.Append((DefaultValue != null)?renderDefaultValue():"");
			sb.Append((Required)?renderRequired():"");
			sb.Append((AlertRequiredString != "")?renderAlertRequiredString():"");
			sb.Append((GridControl)?renderGridControl():"");
			sb.Append((InvokeOnChange != "")?renderInvokeOnChange():"");
			sb.Append((InvokeOnActivate != "")?renderInvokeOnActivate():"");
			sb.Append((InvokeOnDeleteValue != "")?renderInvokeOnDeleteValue():"");
			sb.Append((ToolTip)?renderToolTip():"");
			sb.Append(renderAlertInvalidString());
			sb.Append(renderGridID());
			sb.Append(" InitialValue=\"\" onactivate=\"OnHSelectionFocus(this);\" onbeforedeactivate=\"OnHSelectionBlur(this);\" ");
			sb.Append(" onkeydown=\"OnHControlKeyDown(this)\" onkeyup=\"OnHSelectionKeyUp(this);\" ondragenter=\"event.returnValue=false;\" />");

			sb.Append("<input tabIndex=-1 onclick=\"event.returnValue=false;OnHSelectionClick(this);\" OnOpenSelection=\""+m_OnOpenSelection+"\" ");
			sb.Append(" type=\"image\" GridId=\""+GridId+"\" src=\"" + PathPrefix + m_ImageUrl + "\" style=\"vertical-align:middle;display:none;width:15;height:16\" />");

			output.Write(sb.ToString());
		}
	}
}
